﻿using System;
using System.Collections.Generic;
using Gp.Scripts.Core;
using Gp.Scripts.Data;
using Gp.Scripts.Data.Skills;

namespace Gp.Scripts.Equip {
    [Serializable]
    public class MeleeWeaponInfo : WeaponTypeInfo<MeleeBaseWeaponType> {
        public bool isCharged;
        private bool IsCharged => WeaponType.canCharge && isCharged;

        // /// <summary>
        // /// 回合结束时是否保持充能状态
        // /// </summary>
        // public bool KeepCharged { get; set; }
        
        // 剩余耐久度
        public int curDurability;


        public override bool IsBroken {
            get => curDurability <= 0;
            set => curDurability = value ? 0 : WeaponType.durability;
        }


        public override int GetDamage() {
            if (curDurability <= 0) {
                return 0;
            }


            // 剩余耐久如果小于0， 则返回 1
            return IsCharged ? WeaponType.chargeDamage : WeaponType.damage;
        }

        public int BreakThroughCount() {
            return  IsCharged ? WeaponType.chargeBreakthrough : WeaponType.breakThrough;
        }


        public MeleeWeaponInfo(MeleeBaseWeaponType type, WeaponEntity weaponEntity) : base(type, weaponEntity) {
            curDurability = type.durability;
        }


        public override void SmallTurnEnd(TurnState state) {
            // if (state != TurnState.Attack) return;
            
            // if (!KeepCharged)
            isCharged = false;
        
            // KeepCharged = false;
        }


        // public override void AfterAttack(BaseUnit target, AttackActionResult res) {
        //     // 更新充能
        //     isCharged = false;
        // }


        // public override void AfterDefence(AttackReactionArgs args) {
        //     // 获取攻击者耐久伤害加成
        //     var v = args.Attacker.SkillModifiedData(SkillField.DurabilityHurt, 1);
        //     curDurability = Math.Max(0, curDurability - v.TotalInt());
        // }


        public override IEnumerable<WeaponAbilityEntity> WeaponAbilities() {
            // yield return WeaponAbilityEntity.Build<ChargeWeaponAbilityData>(Entity);
            // if (WeaponType.canCharge)
            //     yield return WeaponAbilityEntity.Build<ActivateWeaponAbilityConfig>(Entity);
            yield break;
        }


    }
}